<template>
    <view class="container">
        <!-- 顶部导航栏 -->
        <!-- <view class="header">
            <text class="title">我的游记</text>
            <view class="add-btn" @click="handleAddTravel">
                <text class="add-icon">+</text>
                <text class="add-text">写游记</text>
            </view>
        </view> -->
        <uni-nav-bar :fixed="true" background-color="#FFF" :border="false" status-bar left-icon="left" left-text="返回"
			title="我的游记" @clickLeft="back" />

        <view class="content">

        <!-- 游记列表 -->
        <scroll-view scroll-y="true" class="travel-list">
            <view v-for="(item, index) in travelNotes" :key="index" class="travel-item" @click="handleTravelClick(item)">
                
                <!-- 游记内容 -->
                <view class="travel-content">
                    <text class="travel-title">{{item.report_title}}</text>
                    <text class="travel-desc">{{item.report_content}}</text>
                    
                    <!-- 底部信息 -->
                    <!-- <view class="travel-footer">
                        <view class="travel-stats">
                            <view class="stat-item">
                                <image src="/static/icons/view.png" class="stat-icon"></image>
                                <text class="stat-num">{{item.views}}</text>
                            </view>
                            <view class="stat-item">
                                <image src="/static/icons/like.png" class="stat-icon"></image>
                                <text class="stat-num">{{item.likes}}</text>
                            </view>
                            <view class="stat-item">
                                <image src="/static/icons/comment.png" class="stat-icon"></image>
                                <text class="stat-num">{{item.comments}}</text>
                            </view>
                        </view>
                        <text class="travel-time">{{item.createTime}}</text>
                    </view> -->
                    <view class="travel-time">{{formatDate(item.created_at)}}</view>
                </view>
                <view v-if="item.img_urls.length > 0" class="travel-images">
                    <image v-for="(image, index) in item.img_urls" :key="index" :src="image" mode="aspectFill" class="travel-image"></image>
                </view>
            </view>
        </scroll-view>

        <!-- 空状态 -->
        <view v-if="travelNotes.length === 0" class="empty-state">
            <image src="/static/icons/empty.png" class="empty-icon"></image>
            <text class="empty-text">还没有游记哦，快去写一篇吧~</text>
        </view>
        </view>

    </view>
</template>

<script setup>
import { ref, onMounted } from 'vue'

// 游记数据
const travelNotes = ref([
])

onMounted(() => {
    loadTravelNotes();
})

function loadTravelNotes() {
    uni.request({
        url: 'https://tushuoit.com/api/ju/travel_share/get_all',
        method: 'GET',
        success: (res) => {
            console.log("loadTravelNotes success:", res);
            travelNotes.value = res.data.data;
        },
        fail: (err) => {
            console.error("loadTravelNotes fail:", err);
        }
    })  
}

function formatDate(dateString) {
  const date = new Date(dateString);
  return `${date.getMonth() + 1}月${date.getDate()}日`;
}

// 处理点击游记
const handleTravelClick = (item) => {
    uni.navigateTo({
        url: `/pages/youji/detail?travel_id=${item.id}`
    })
}

// 处理添加游记
const handleAddTravel = () => {
    uni.navigateTo({
        url: '/pages/travel/edit'
    })
}

const back = () => {
    uni.navigateBack();
}

</script>

<style>
.container {
    min-height: 100vh;
    background-color: #f8f0e3;
}

.content {
    padding: 30rpx;
}

.travel-images {
    display: flex;
    flex-wrap: wrap;
    gap: 10rpx;
    margin: 30rpx;
}

.travel-image {
    width: 200rpx;
    height: 200rpx;
}


.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20rpx 30rpx;
    background-color: #fff;
    border-radius: 16rpx;
    margin-bottom: 20rpx;
}

.nav-bar {
    height: calc(var(--status-bar-height) + var(--navigation-bar-height));
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20rpx 30rpx;
    background-color: #fff;
}

.title {
    font-size: 36rpx;
    font-weight: bold;
    color: #333;
}

.add-btn {
    display: flex;
    align-items: center;
    background-color: #ed8e40;
    padding: 12rpx 24rpx;
    border-radius: 30rpx;
}

.add-icon {
    color: #fff;
    font-size: 32rpx;
    margin-right: 8rpx;
}

.add-text {
    color: #fff;
    font-size: 28rpx;
}

.travel-list {
    height: calc(100vh - 120rpx);
}

.travel-item {
    background-color: #fff;
    border-radius: 16rpx;
    margin-bottom: 20rpx;
    overflow: hidden;
}

.travel-cover {
    position: relative;
    height: 360rpx;
}

.cover-image {
    width: 100%;
    height: 100%;
}

.travel-date {
    position: absolute;
    right: 20rpx;
    bottom: 20rpx;
    background-color: rgba(0, 0, 0, 0.6);
    color: #fff;
    padding: 8rpx 16rpx;
    border-radius: 8rpx;
    font-size: 24rpx;
}

.travel-content {
    padding: 20rpx;
}

.travel-title {
    font-size: 32rpx;
    font-weight: bold;
    color: #333;
    margin-bottom: 12rpx;
}

.travel-desc {
    font-size: 28rpx;
    color: #666;
    line-height: 1.6;
    margin-bottom: 20rpx;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
}

.travel-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1rpx solid #eee;
    padding-top: 20rpx;
}

.travel-stats {
    display: flex;
    align-items: center;
}

.stat-item {
    display: flex;
    align-items: center;
    margin-right: 30rpx;
}

.stat-icon {
    width: 32rpx;
    height: 32rpx;
    margin-right: 8rpx;
}

.stat-num {
    font-size: 24rpx;
    color: #999;
}

.travel-time {
    font-size: 24rpx;
    color: #999;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 60vh;
}

.empty-icon {
    width: 200rpx;
    height: 200rpx;
    margin-bottom: 20rpx;
}

.empty-text {
    font-size: 28rpx;
    color: #999;
}
</style>